const express = require('express')
const app = express()

app.use(express.urlencoded())
app.use(express.json())

app.use((req,res,next)=>{

    res.set("Access-Control-Allow-Origin", '*')
    res.set("Access-Control-Allow-Headers", "token")
    next()
})

app.post('/user',(req,res)=>{
    const {
        name
    }= req.body
    // console.log(req);
    if(name !== '002'){
        return res.send({
            code:402,
            msg :'数据错误',
            data:null

        })
    }
    res.send({
        code:200,
        msg:'数据成功',
        data:{
            name:'章陈宫',
            age:18,
            sex:'女'
        }
    })
    
    

})
app.get('/1',(req,res)=>{
    res.sendFile(__dirname+'/拦截器练习.html')
})
app.listen(8090,()=>{
    console.log('打印:http://127.0.0.1:8090');
})